// 版权归 瞄你个汪 所有。使用本代码应遵守相关法律法规和Apache 2.0开源许可要求。
package top.geeke.toolkit.http;

import lombok.Getter;
import top.geeke.eunm.SysErrorEnum;

/**
 * <p>
 * 自定义异常
 * </p>
 * @author 瞄你个汪
 * @since 2024-05-01 12:00:00
 */
@Getter
public class AppException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    /**
     * 错误码
     */
    private final int code;

    public AppException(Throwable cause) {
        super(cause.getMessage(), cause);
        this.code = ResultEnum.R400.code;
    }

    public AppException(ResultEnum result, Throwable cause) {
        super(cause.getMessage(), cause);
        this.code = result.code;
    }

    public AppException(String errorMsg) {
        super(errorMsg);
        this.code = ResultEnum.R400.code;
    }

    public AppException(String errorMsg, Object... args) {
        super(String.format(errorMsg, args));
        this.code = ResultEnum.R400.code;
    }

    public AppException(SysErrorEnum error) {
        super(error.text);
        this.code = error.value;
    }

    public AppException(SysErrorEnum error, Object... args) {
        super(String.format(error.text, args));
        this.code = error.value;
    }

    public AppException(int code, String errorMsg) {
        super(errorMsg);
        this.code = code;
    }

    public AppException(int code, String errorMsg, Throwable cause) {
        super(errorMsg, cause);
        this.code = code;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }
}
